package nsl.com.util.excel.bean;


import nsl.com.util.excel.basic.UtilExcelCoordinateConverter;

/**
 * Description:
 * Created by E460 on 2017/10/16.
 */
public class SheetHead {

    //A1:H2
    private String area;
    //min=0
    private int top;
    //min=0
    private int left;
    private int right;
    private int bottom;

    public SheetHead(String area){
        this.area=area.toUpperCase();
        String coordinates[]=area.split(":");
        if(coordinates==null || coordinates.length !=2){
            throw new RuntimeException("输入的坐标格式不正确，请输入类似: A1:H3 这种形式的坐标字符串");
         }
        ExcelPoint leftTop= UtilExcelCoordinateConverter.convertCellAddressFromString2Point(coordinates[0]);
        ExcelPoint rightBottom=UtilExcelCoordinateConverter.convertCellAddressFromString2Point(coordinates[1]);
        top=leftTop.getY();
        left=leftTop.getX();
        bottom=rightBottom.getY();
        right=rightBottom.getX();
    }

    public SheetHead(int top, int left, int bottom, int right){
        if(top<0 || left<0 || bottom<0 || right <0){
            throw new RuntimeException("输入坐标中有小于0.");
        }
        this.left=left;
        this.top=top;
        this.bottom=bottom;
        this.right=right;
        String leftTop=UtilExcelCoordinateConverter.convertColumnAddressFromIndex2Letter(left)+top;
        String rightBottom=UtilExcelCoordinateConverter.convertColumnAddressFromIndex2Letter(right)+bottom;
        area=leftTop+":"+rightBottom;
    }

    @Override
    public String toString() {
        return "SheetHead{" +
                "area='" + area + '\'' +
                ", top=" + top +
                ", left=" + left +
                ", right=" + right +
                ", bottom=" + bottom +
                '}';
    }

    public String getArea() {
        return area;
    }

    public void setArea(String area) {
        this.area = area;
    }

    public int getTop() {
        return top;
    }

    public void setTop(int top) {
        this.top = top;
    }

    public int getLeft() {
        return left;
    }

    public void setLeft(int left) {
        this.left = left;
    }

    public int getRight() {
        return right;
    }

    public void setRight(int right) {
        this.right = right;
    }

    public int getBottom() {
        return bottom;
    }

    public void setBottom(int bottom) {
        this.bottom = bottom;
    }
}
